#include "system.h"
#include "interrupt.h"
#include "alarm.h"

static void
interrupt_handler(int which) {
    scheduler->ReadyToRun((Thread*)which);
}

void
Alarm::GoToSleepFor(int howLong) {
    IntStatus oldLevel = interrupt->SetLevel(IntOff);

    interrupt->Schedule(interrupt_handler, (int) currentThread,
                        howLong, TimerInt);

    currentThread->Sleep();

    (void) interrupt->SetLevel(oldLevel);
}
